package linear;

import java.util.Stack;

public class TwoStackQueueRedBookInterview<E>{
    private Stack<E> s1 = new Stack<>();
    private Stack<E> s2 = new Stack<>();
    public void add(E e) {
        s1.push(e);
    }
    public E remove() {
        if(s2.isEmpty()){
        while (!s1.isEmpty())
            s2.push((s1.pop()));}
        return s2.pop();
    }

    public static void main(String[] args) {
        TwoStackQueueRedBookInterview<Integer> myQ = new TwoStackQueueRedBookInterview<>();
        myQ.add(1);
        myQ.add(2);
        System.out.println(myQ.remove());
        myQ.add(3);
        System.out.println(myQ.remove());
        System.out.println(myQ.remove());
    }
}
